#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int N=410;
int a[N];
int s[N];
int f[N][N];
int g[N][N];
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i],a[i+n]=a[i];
    
    for(int i=1;i<=2*n;i++) s[i]=s[i-1]+a[i];
    
    memset(f,0x3f,sizeof(f));
    memset(g,-0x3f,sizeof(g));
    
    for(int len=1;len<=n;len++)
    {
        for(int l=1;l+len-1<=2*n;l++)
        {
            int r=l+len-1;
            if(len==1) f[l][r]=g[l][r]=0;
            for(int k=l;k<r;k++)
            {
                f[l][r]=min(f[l][r],f[l][k]+f[k+1][r]+s[r]-s[l-1]);
                g[l][r]=max(g[l][r],g[l][k]+g[k+1][r]+s[r]-s[l-1]);
            }
        }
    }
    int ans1=0x3f3f3f3f;
    int ans2=-0x3f3f3f3f;
    for(int i=1;i+n-1<2*n;i++)
    {
        int l=i,r=n+i-1;
        ans1=min(ans1,f[l][r]);
        ans2=max(ans2,g[l][r]);
    }
    cout<<ans1<<endl<<ans2;
    return 0;
}
